import Taro, { Component } from '@tarojs/taro'
import { View, Text ,Picker} from '@tarojs/components'
import {AtList, AtListItem,AtIcon, AtModal} from 'taro-ui'
import './consultsetting.css'
// import reactMixin from 'react-mixin';
// import myJs from './wenzhenshezhiJs.js'
import app from '../../../../main.js'

export default class ConsultSetting extends Component {
    config = {
        navigationBarTitleText: '问诊设置'
    }
    constructor(){
        super(...arguments);
        this.state={
            isOpened:false,
            isOpened1:false,
            isOpened2:false,
            selector: ['10','20','30','50','60','80','100','200','300','500','600','800','1000','1200','2000','3000'],
            selectorDf1:10,
            selectorDf2:0,
            selector2: ["免费",'10','20','30','50','60','80','100','200','300','500','600','800','1000','1200','2000','3000'],
            switchOpen1:false,
            switchOpen2:false,
            switchOpen3:false,
            swtrueOrfalse:'',
            disabled1:true,
            disabled2:true,
            allTime:[],
            length:0,
            doctor: {}
        }
    }

    handleClose(){
        this.setState({
            isOpened:false
        })
    }
    
    //
    getQuestion(e){
        e.stopPropagation();
        this.setState({
            isOpened:true
        })
    }
    handleClose1(){
        this.setState({
            isOpened1:false
        })
    }

    getQuestion1(e){
        e.stopPropagation();
        this.setState({
            isOpened1:true
        })
    }

    handleClose2(){
        this.setState({
            isOpened2:false
        })
    }

    getQuestion2(e){
        e.stopPropagation();
        this.setState({
            isOpened2:true
        })
    }

    getDoctorCode() {
        var auth_status = this.state.doctor.auth_status;
        if (auth_status == '资质通过') {
            return 1;   // 可修改
        } else if (auth_status == '资质审核中') {
            return 3;   // 不可修改
        } else {
            return 2;   // 要去资质审核
        }
    }

    //改变专家咨询价格
    onChange1  = e => {
        let index = e.detail.value
        let itemMoney = this.state.selector[index]
        if(this.state.switchOpen1){
            this.setState({
                selectorDf1:itemMoney
            },()=>{
                let data = {is_open_inquiry_direction:'开通',inquiry_directional_price:this.state.selectorDf1}
                app.post('web/inquirySetting/inquirySetting', data, (res)=>{
                    console.log('改变专家咨询价格')
                })
            })
        }
    }
    
    //改变随访追问包价格
    onChange2 = e =>{
        let index = e.detail.value
        let itemMoney = this.state.selector2[index]
        if(this.state.switchOpen3){
            this.setState({
                selectorDf2:itemMoney
            },()=>{
                let data = {is_open_flow:'是',flow_trace_price:this.state.selectorDf2}
                app.post('web/inquirySetting/inquirySetting', data, (res)=>{
                    console.log('改变随访追问包价格')
                })
            })
        }
    }
    
    //点击专家咨询
    onSwitchOpen(){
        var code = this.getDoctorCode();
        if (code == 2) {
            app.navigateTo('../../../center/pages/zizhibeian/zizhibeian');
            return;
        } else if (code == 3) {
            app.toastMessage('资质正在审核中，暂不可操作');
            return;
        }
        if(this.state.switchOpen1 == false){
            this.setState({
                switchOpen1:true,
                disabled1:false
            },()=>{
                let data = {is_open_inquiry_direction:'开通',inquiry_directional_price:this.state.selectorDf1}
                app.post('web/inquirySetting/inquirySetting', data, (res)=>{
                    console.log('开启专家咨询',this.state.disabled1)
                })
            }) 
        }else{
            this.setState({
                switchOpen1:false,
                disabled1:true
            },()=>{
                let data = {is_open_inquiry_direction:'关闭',inquiry_directional_price:this.state.selectorDf1}
                app.post('web/inquirySetting/inquirySetting', data, (res)=>{
                    console.log('关闭专家咨询',this.state.disabled1)
                })
            })
        }
    }
    
    //点击快速咨询
    handleChange(event){
        var code = this.getDoctorCode();
        if (code == 2) {
            app.navigateTo('../../../center/pages/zizhibeian/zizhibeian');
            return;
        } else if (code == 3) {
            app.toastMessage('资质正在审核中，暂不可操作');
            return;
        }
        if(this.state.switchOpen2 == false){
            this.setState({
                switchOpen2:true
            },()=>{
                let data = {is_open_inquiry_no_direction:'开通'}
                app.post('web/inquirySetting/inquirySetting', data, (res)=>{
                    console.log('开启快速咨询')
                })
            }) 
        }else{
            this.setState({
                switchOpen2:false
            },()=>{
                let data = {is_open_inquiry_no_direction:'关闭'}
                app.post('web/inquirySetting/inquirySetting', data, (res)=>{
                    console.log('关闭快速咨询')
                })
            })
        }
    }

    //点击随访包价格
    onSwitchOpen3(event){
        var code = this.getDoctorCode();
        if (code == 2) {
            app.navigateTo('../../../center/pages/zizhibeian/zizhibeian');
            return;
        } else if (code == 3) {
            app.toastMessage('资质正在审核中，暂不可操作');
            return;
        }
       if(this.state.switchOpen3 == false){
            this.setState({
                switchOpen3:true,
                disabled2:false
            },()=>{
                let data = {is_open_flow:'是',flow_trace_price:this.state.selectorDf2}
                app.post('web/inquirySetting/inquirySetting', data, (res)=>{
                    console.log('开启随访包价格',this.state.disabled2)
                })
            }) 
        }else{
            this.setState({
                switchOpen3:false,
                disabled2:true
            },()=>{
                let data = {is_open_flow:'否',flow_trace_price:this.state.selectorDf2}
                app.post('web/inquirySetting/inquirySetting', data, (res)=>{
                    console.log('关闭随访包价格',this.state.disabled2)
                })
            })
        }
    }
    
    orSet1(){
        if(this.state.switchOpen1 == false){
            Taro.showModal({
                title: '提示',
                content: '需要打开专家咨询咨询按钮才可设置',
                showCancel:false
              })
        }
    }

    gotoTheNext(){
        let me = this
        if(me.state.switchOpen2 == true){
            app.navigateTo('../Receipt/Receipt')
        }else{
            Taro.showModal({
                title: '提示',
                content: '需要打开快速咨询按钮才可设置',
                showCancel:false
              })
        }
    }

    orSet3(){
        if(this.state.switchOpen3 == false){
            Taro.showModal({
                title: '提示',
                content: '需要打开随访追问包按钮才可设置',
                showCancel:false
              })
        }
    }

    
    // 获取设置
    getData(){
        let me = this
        let data ={}          //专家咨询
        let timeData = {}     //快速可接单时间列表
        let openOrclose1 = false
        let openOrclose2 = false
        let openOrclose3 = false
        app.get('web/inquirySetting/inquirySettingData',data,function(res){
            console.log(res);
            if(res.data.result.is_open_inquiry_direction == "开通" ){     //  是否开通专家咨询
                openOrclose1 = true
                me.setState({
                    disabled1:false,
                    switchOpen1: openOrclose1,     //  是否开通专家咨询
                })
            }else{
                // openOrclose1 = false
                me.setState({
                    switchOpen1: openOrclose1,     //  是否开通专家咨询
                })
            }
            if(res.data.result.is_open_inquiry_no_direction == "开通"){   //  是否开通快速咨询
                openOrclose2 = true
                me.setState({
                    isabled2:false,
                    switchOpen2: openOrclose2,     //  是否开通快速咨询
                })
            }else{
                openOrclose2 = false
                me.setState({
                    switchOpen2: openOrclose2,     //  是否开通快速咨询
                })
            }
            if(res.data.result.is_open_flow == "是"){   //  是否开通随访追问包
                openOrclose3 = true
                 me.setState({
                    disabled2:false,
                    switchOpen3: openOrclose3,     //  是否开通随访追问包
                })
            }else{
                openOrclose3 = false
            }
            me.setState({
                // switchOpen1: openOrclose1,     //  是否开通专家咨询
                // switchOpen2: openOrclose2,     //  是否开通快速咨询
                // switchOpen3: openOrclose3,     //  是否开通随访追问包
                selectorDf1:res.data.result.inquiry_directional_price,
                selectorDf2:res.data.result.flow_trace_price
            },()=>{
                console.log(123,me.state.switchOpen1,me.state.switchOpen2,me.state.selectorDf1)
            })
        })
        app.get('web/inquirySetting/quickInquirySettingData', timeData, (res)=>{
            let dataArr = res.data.result.list
            me.setState({
                allTime:dataArr
            },()=>{
                this.setState({
                    length:this.state.allTime.length
                })
            })
        })
    }
    getDoctor() {
        var me = this;
        app.get('web/doctor/get', {}, function(res) {
            me.setState({
                doctor: res.data.result
            })
        })   
    }
    componentDidMount(){
        this.getData();
        this.getDoctor();
    }

    render () {
        return (
            <View className='consult-setting'>
                {/*专家咨询*/}
                <AtList  className='box' hasBorder={false}>
                    <AtIcon className='icon' value='help' size='24' color='#aeaeae' onClick={this.getQuestion.bind(this)}></AtIcon>
                    <AtListItem title='专家咨询' isSwitch switchColor='#72d021'  hasBorder={false} switchIsCheck={this.state.switchOpen1} onSwitchChange={this.onSwitchOpen.bind(this)}/>
                    <AtModal
                        isOpened={this.state.isOpened}
                        title='专家咨询'
                        confirmText='关闭提示'
                        onClose={ this.handleClose.bind(this) }
                        onConfirm={ this.handleClose.bind(this) }
                        content={"• 开通专家咨询后，患者即可定向向您发起咨询订单，咨询的价格由您来设定"+
                                  "• 在收到患者专家咨询订单后，请您在方便的时候尽快给予患者回复"+
                                  "• 如果24小时内您都没有回复，则咨询费用会自动退还给患者"}
                    />
                </AtList>
                <AtList className='part box'>
                    <AtListItem title='专家咨询价格（元/次)' arrow='right' hasBorder={false} onClick={this.orSet1.bind(this)}/>
                    <Picker disabled={this.state.disabled1} className='picker' mode='selector' range={this.state.selector} onChange={this.onChange1.bind(this)}>
                       {this.state.selectorDf1}
                    </Picker>
                </AtList>
                {/*快速咨询*/}
                <AtList  className='box' hasBorder={false}>
                    <AtIcon className='icon' value='help' size='24' color='#aeaeae' onClick={this.getQuestion1.bind(this)}></AtIcon>
                    <AtListItem title='快速咨询' isSwitch switchColor='#72d021'  hasBorder={false} switchIsCheck={this.state.switchOpen2} onSwitchChange={this.handleChange.bind(this)}/>
                    <AtModal
                        isOpened={this.state.isOpened1}
                        title='快速咨询'
                        confirmText='关闭提示'
                        onClose={ this.handleClose1.bind(this)}
                        onConfirm={ this.handleClose1.bind(this) }
                        content={"• 开通快速咨询后，系统即可根据您响应患者咨询的速度和质量来把患者非指定医生的咨询订单分派给您来接单，咨询的价格由平台统一定价"+
                                  "• 在收到患者专家咨询订单后，请您在10分钟内接单回复，超过十分钟则订单会重新派单给其他医生"}
                    />
                </AtList>
                <AtList className='part'>
                    <AtListItem title='快速咨询可接单时间' extraText={this.state.length == 0 ? '未设置' : '已设置'} arrow='right' hasBorder={false} onClick={this.gotoTheNext.bind(this)}/>
                </AtList>
                {/*随访追问包*/}
                <AtList  className='box last_box' hasBorder={false}>
                    <AtIcon className='icon' value='help' size='24' color='#aeaeae' onClick={this.getQuestion2.bind(this)}></AtIcon>
                    <AtListItem title='随访追问包' isSwitch switchColor='#72d021'  hasBorder={false} switchIsCheck={this.state.switchOpen3} onSwitchChange={this.onSwitchOpen3.bind(this)}/>
                    <AtModal
                        isOpened={this.state.isOpened2}
                        title='随访追问包'
                        confirmText='关闭提示'
                        onClose={ this.handleClose2.bind(this) }
                        onConfirm={ this.handleClose2.bind(this) }
                        content={"• 随访追问包是指您在发起随访后，患者向您进行随访咨询的追问包，追问包建议设置为免费，这样有助于患者获得更好的咨询体验"+
                                  "• 您也可以自主设定随访追问包的价格，每个追问包包括三个回合对话"}
                    />
                </AtList>

                <AtList className='part box'>
                    <AtListItem title='随访追问包价格（元/次)' arrow='right' hasBorder={false} onClick={this.orSet3.bind(this)}/>
                    <Picker disabled={this.state.disabled2} className='picker' mode='selector' range={this.state.selector2} onChange={this.onChange2.bind(this)}>
                       {this.state.selectorDf2}
                    </Picker>
                </AtList>
            </View>
        );
    }
}
// reactMixin.onClass(Wenzhenshezhi,myJs);